package edu.zut.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "JSPServlet", value = "/jsp/demo1")
public class JSPServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //往request、session、servletContext、cookie中添加数据
        request.setAttribute("myName","xueyin");
        request.setAttribute("myAge",30);
        HttpSession session = request.getSession();
        session.setAttribute("myAge",22);
        ServletContext context = request.getServletContext();
        context.setAttribute("school","中原工学院软件学院");
        Cookie cookie = new Cookie("myPhone", "15937190214");
        response.addCookie(cookie);
        //转发
        request.getRequestDispatcher("/demo1.jsp").forward(request,response);


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
